package com.miku.blog.controller;


import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.Category;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author shkstart
 * @create ${}YEAR-05-30 2:28
 */
@Api(tags = "后台管理系统[文章分类]")
@RequestMapping("/admin")
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @SystemLog(notes = "获取分类列表{后台管理系统}")
    @ApiOperation(value = "获取分类接口", notes = "获取所有分类进行分类管理")
    @GetMapping("/categories")
    public ResponseResult categories(@RequestParam("current") Integer current,
                                     @RequestParam("size") Integer size,
                                     @RequestParam(value = "keywords", required = false) String keywords)
    {
        return categoryService.categories(current, size, keywords);
    }

    @SystemLog(notes = "添加或修改分类{后台管理系统}")
    @ApiOperation(value = "添加或修改分类接口", notes = "新增/修改文章分类")
    @PostMapping("/categories")
    public ResponseResult addCategories(@RequestBody Category category) {
        return categoryService.addCategories(category);
    }


    @SystemLog(notes = "删除分类{后台管理系统}")
    @ApiOperation(value = "删除分类接口", notes = "批量删除文章分类 { 当该分类下无对应文章时 }")
    @DeleteMapping("/categories")
    public ResponseResult deleteCategories(@RequestBody Integer[] categoryIdList) {
        return categoryService.deleteCategories(categoryIdList);
    }


    @SystemLog(notes = "搜索文章分类{文章发布分类选项}{后台管理系统}")
    @ApiOperation(value = "搜索文章分类{文章发布分类选项}接口", notes = "搜索文章分类{文章发布分类选项} 支持自定义分类名称")
    @GetMapping("/categories/search")
    public ResponseResult getCategoryList(){
        return categoryService.getCategoryList();
    }


}
